package com.rlz.aspectj.util;

import java.util.concurrent.TimeUnit;

public class StopWatch {
    private long mStartTime;
    private long mEndTime;
    private long mElapsedTime;

    public StopWatch() {
        //empty
    }

    private void reset() {
        mStartTime = 0;
        mEndTime = 0;
        mElapsedTime = 0;
    }

    public void start() {
        reset();
        mStartTime = System.nanoTime();
    }

    public void stop() {
        if (mStartTime != 0) {
            mEndTime = System.nanoTime();
            mElapsedTime = mEndTime - mStartTime;
        } else {
            reset();
        }
    }

    public long getTotalTimeMillis() {
        return (mElapsedTime != 0) ? TimeUnit.NANOSECONDS.toMillis(mEndTime - mStartTime) : 0;
    }
}